package com.zzyang.cloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * TODO
 *
 * @author zhuoziyang
 * @date 2020/10/27 21:52
 */
@RestController

public class PaymentHystirxController {

    @GetMapping("/payment/hystrix/ok")
    public String ok() {
        return "ok-----" + UUID.randomUUID().toString();
    }

    @GetMapping("/payment/hystrix/wrong")
    @HystrixCommand(fallbackMethod = "wrongHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String wrong() {
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "wrong-----" + UUID.randomUUID().toString();
    }

    public String wrongHandler() {
        return "o(╥﹏╥)o";
    }

}
